/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package beans;

import core.Course;
import core.Program;
import core.School;
import java.util.Collection;

/**
 *  Uses decorator pattern to extend School class to get neccesary "bean properties"
 * @author Peter
 */

public class SimpleSchoolBean {

        boolean selected;
        School school;
        String[] statusMessage = {
          "unknown",
          "could not connect",
          "update suceeded"
        };

        int status;

    /** Creates a new instance of SimpleSchoolBean */
    public SimpleSchoolBean(School school) {
        this.school = school;
        this.selected = false;
        status = 0;
    }

    /**
     * creates a cloned bean out of input,
     * all elements _except_ programs and courses are cloned.
     * @param toBeCloned
     */
    public SimpleSchoolBean(SimpleSchoolBean toBeCloned)
    {

        school = new School(
                toBeCloned.getId(),
                toBeCloned.getName(),
                toBeCloned.getDescription(),
                toBeCloned.getWebLink(),
                toBeCloned.getXmlSource()
                );

        selected = false;
        status = 0;

    }

    public String getXmlSource() {
        return school.getXMLSource();
    }

    public void setXmlSource(String XMLSource) {
        school.setXMLSource(XMLSource);
    }

    public Collection<Course> getCourses() {
        return school.getCourses();
    }

    public void setBooks(Collection<Course> courses) {
        school.setCourses(courses);
    }

    public Collection<Program> getPrograms()
    {
        return school.getPrograms();
    }

    public void setPrograms(Collection<Program> programs)
    {
        school.setPrograms(programs);
    }
    /**
     *
     * @return
     */
    public long getId() {
        return school.getId();
    }

    /**
     *
     * @return
     */
    public String getName() {
        return school.getName();
    }

    /**
     *
     * @return
     */
    public String getDescription() {
        return school.getDescription();
    }

    /**
     *
     * @return
     */
    public String getWebLink() {
        return school.getWebLink();
    }

    /*
     *  Set methods
     */
    /**
     *
     * @param id
     */
    public void setId(long id) {
        school.setId(id);
    }

    /**
     *
     * @param name
     */
    public void setName(String name) {
        school.setName(name);
    }

    /**
     *
     * @param description
     */
    public void setDescription(String description) {
        school.setDescription(description);
    }

    /**
     *
     * @param webLink
     */
    public void setWebLink(String webLink) {
        school.setWebLink(webLink);
    }

        public boolean getSelected()
    {
        // for debugging
        //System.out.println("getSelecten");
        return selected;
    }
    /**
     * get selection
     * @param selected
     */
    public void setSelected(boolean selected)
    {
        // for debugging
        //if(selected == true) System.out.println(user.getId() + "Selected");
        //if(selected == false) System.out.println(user.getId() + "unselected");
        this.selected = selected;
    }

    public void setSchool(School school)
    {
        this.school = school;
    }

    public School getSchool()
    {
        return school;
    }

    public String getStatus()
    {
        if(status > statusMessage.length)
            return statusMessage[0];
        else
            return statusMessage[status];
    }

    public void setStatus(String status)
    {
        int i= 0;
        for(String message: statusMessage)
        {
            if(message.equals(status))
                break;
            i++;
        }
        if(i > statusMessage.length)
            this.status = 0;
        else this.status = i;
    }
    
    public void setStatusByInt(int newStatus)
    {
        if(newStatus > statusMessage.length)
            status = 0;
        else
            status = newStatus;
    }


}
